package com.lxq.LeetCode.countAndSay;

public class Solution {
    public static void main(String[] args) {
        System.out.println(countAndSay(30));
    }

    public static String countAndSay(int n) {
        if (n == 1) {
            System.out.println(1);
            return "1";
        }
        StringBuilder res = new StringBuilder();
        String pendingStr = countAndSay(n - 1);
        pendingStr += "z";
        for (int j = 0, i = 1; i < pendingStr.length(); i++) {
            if (pendingStr.charAt(j) != pendingStr.charAt(i)) {
                res.append(i - j).append(pendingStr.charAt(j));
                j = i;
            }
        }
        return res.toString();
    }
}
